//
//  main.cpp
//  160.只出现一次的数字
//
//  Created by Yan Zihao on 2024/10/4.
//

#include <iostream>
#include<vector>
using namespace std;

/*class Solution
{
public:
    vector<int> singleNumber(vector<int>& nums)
    {
        int count[10] = {0};
        vector<int> answer;
        for(int num : nums)
        {
            count[num]++;
        }
        for (int i = 0; i < 10; i++)
        {
            if(count[i] == 1)
            {
                answer.push_back(i);
            }
            return answer;
        }
        return answer;
    }
};*/

class Solution
{
public:
    vector<int> singleNumber(vector<int>& nums)
    {
        int xorsum = 0;
        for (int num: nums)
        {
            xorsum ^= num;
        }
        // 防止溢出
        int lsb = (xorsum == INT_MIN ? xorsum : xorsum & (-xorsum));
        int type1 = 0, type2 = 0;
        for (int num: nums)
        {
            if (num & lsb)
            {
                type1 ^= num;
            }
            else
            {
                type2 ^= num;
            }
        }
        return {type1, type2};
    }
};
